﻿using System;
using Zeus.Thunder.Core;

namespace SharpTrainer.Delegates
{
    class SimpleFunc : ITestCase
    {
        public void Run()
        {
            Console.WriteLine("Using an anonymous method:");
            AnonymousMethod();

            Console.WriteLine("Using lambda expression:");
            LamdaTest();

            Console.Read();
        }

        //Using an anonymous method to create a delegate instance
        public void AnonymousMethod()
        {
            Func<string> returnHello;
            Func<string, string> returnContent;
            Func<string, int> returnLength;

            returnHello = delegate() { return "Hello World!"; };
            returnContent = delegate(string text) { return text; };
            returnLength = delegate(string text) { return text.Length; };

            Console.WriteLine(returnHello());
            Console.WriteLine(returnContent("Hello David!"));
            Console.WriteLine("Length of content: " + returnLength("Hello David!"));
        }

        //Using lambda expression
        public void LamdaTest()
        {
            Func<string> returnHello;
            Func<string, string> returnContent;
            Func<string, int> returnLength;

            returnHello = () => { return "Hi David!"; };
            returnContent = (string text) => { return text; };
            returnLength = (string text) => { return text.Length; };

            Console.WriteLine(returnHello());
            Console.WriteLine(returnContent("Hi David!"));
            Console.WriteLine("Length of content: " + returnLength("Hi David!"));
        }
    }
}
